package com.bear.fastrepair.mvvm.data.employee

import com.bear.fastrepair.entity.*
import com.bear.fastrepair.mvvm.data.Result
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.withContext
import retrofit2.http.Url
import java.io.File

class EmployeeRepository(private val dataSource: EmployeeSource) {
    suspend fun getOrderInfoPage(
        current: Int,
        size: Int,
        orderStatus: Int?
    ): Result<EmployeeOrderInfoPage> = withContext(Dispatchers.IO) {
        dataSource.getOrderInfoPage(current, size, orderStatus)
    }

    suspend fun updateWorkStatus(workStatus: EmployeeWorkStatus): Result<ResponseInfo> =
        withContext(Dispatchers.IO) {
            dataSource.updateWorkStatus(workStatus)
        }

    suspend fun updateApp() = withContext(Dispatchers.IO) {
        dataSource.updateApp()
    }

    suspend fun downloadApp(@Url fileUrl: String) = withContext(Dispatchers.IO) {
        dataSource.downloadApp(fileUrl)
    }

    suspend fun updateLocation(location: UpdateLocation) = withContext(Dispatchers.IO) {
        dataSource.updateLocation(location)
    }

    suspend fun resetPassword(resetPasswordBean: ResetPasswordBean) = withContext(Dispatchers.IO) {
        dataSource.resetPassword(resetPasswordBean)
    }

    suspend fun getOrderById(id: String): Result<OrderInfoDetail> = withContext(Dispatchers.IO) {
        dataSource.getOrderById(id)
    }

    suspend fun saveBookingTime(serviceOrderId: String, bookingBody: BookingBody) = withContext(Dispatchers.IO) {
        dataSource.saveBookingTime(serviceOrderId, bookingBody)
    }

    suspend fun imageUpload(path: String, params: List<File>): Result<ResponseListInfo> =
        withContext(Dispatchers.IO) {
            dataSource.imageUpload(path, params)
        }

    suspend fun employeeClockIn(
        locationAddress: String,
        locationLatitude: String,
        locationLongitude: String,
        serviceOrderId: String?
    ) = withContext(Dispatchers.IO) {
        dataSource.employeeClockIn(
            locationAddress,
            locationLatitude,
            locationLongitude,
            serviceOrderId
        )
    }

    suspend fun takeMachineBack(
        serviceOrderId: String,
        images: String?,
        remark: String?
    ): Result<ResponseInfo> = withContext(Dispatchers.IO) {
        dataSource.takeMachineBack(serviceOrderId, images, remark)
    }

    suspend fun takeMachineBackRepaired(
        serviceOrderId: String,
        images: String?,
        remark: String?
    ): Result<ResponseInfo> = withContext(Dispatchers.IO) {
        dataSource.takeMachineBackRepaired(serviceOrderId, images, remark)
    }

    suspend fun orderComplete(
        serviceOrderId: String,
        images: String?,
        remark: String?
    ): Result<ResponseInfo> = withContext(Dispatchers.IO) {
        dataSource.orderComplete(serviceOrderId, images, remark)
    }

    suspend fun orderBack(
        serviceOrderId: String,
        images: String?,
        remark: String?
    ): Result<ResponseInfo> = withContext(Dispatchers.IO) {
        dataSource.orderBack(serviceOrderId, images, remark)
    }

    suspend fun addOrderBill(billInfoAdd: BillInfoAdd) = withContext(Dispatchers.IO) {
        dataSource.addOrderBill(billInfoAdd)
    }

    suspend fun getBillInfoById(id: String) = withContext(Dispatchers.IO) {
        dataSource.getBillInfoById(id)
    }

    suspend fun getImagesById(id: String) = withContext(Dispatchers.IO) {
        dataSource.getImagesById(id)
    }

    suspend fun uploadImages(image: EmployeeUploadImage) = withContext(Dispatchers.IO) {
        dataSource.uploadImages(image)
    }

    suspend fun getPersonalInfo() = withContext(Dispatchers.IO) {
        dataSource.getPersonalInfo()
    }
}